﻿using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features;

namespace Transponder_WebApp
{
    public class Program
    {

        /// <summary>
        /// 
        /// </summary>
        public static MessageAgent mMessageAgent { get; private set; }
        public static async Task Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();

            builder.Services.Configure<FormOptions>(x =>
            {
                x.ValueLengthLimit = int.MaxValue; // 设置值长度限制
                x.MultipartBodyLengthLimit = int.MaxValue; // 设置多部分主体的长度限制
            });

            var AllowSpecificOrigin = "AllowSpecificOrigin";

            builder
                .Services
            .AddCors(options =>
            {
                options.AddPolicy(AllowSpecificOrigin,
                    builder => builder
                    .AllowAnyOrigin() // 允许的源，可以添加多个源
                    .AllowAnyMethod() // 允许任何HTTP方法
                    .AllowAnyHeader()); // 允许任何头部

            });


            builder.WebHost.ConfigureKestrel(serverOptions =>
            {
                //serverOptions.ConfigureHttpsDefaults(listenOptions =>
                //{
                //    listenOptions.SslProtocols = SslProtocols.None;
                //});
                serverOptions.ListenAnyIP(8080);

            });


            var app = builder.Build();

            app.UseCors(AllowSpecificOrigin);

            // Configure the HTTP request pipeline.

            app.UseHttpsRedirection();

            app.UseAuthorization();

            app.MapControllers();

            // mMessageAgent = new MessageAgent();
            //    await  mMessageAgent.Open();

            app.Run();
        }
    }
}
